package com.caogen.cg_wl_kt.ui.fragment.notifications

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.view.get
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.viewpager.widget.ViewPager
import com.caogen.cg_wl_kt.adapter.NotificSectionsPagerAdapter
import com.caogen.cg_wl_kt.base.BaseFragment
import com.caogen.cg_wl_kt.databinding.FragmentNotificationsBinding
import com.caogen.cg_wl_kt.utils.YDLog
import com.caogen.cg_wl_kt.vmodel.fragment.NotificationsViewModel
import com.google.android.material.tabs.TabLayout

class NotificationsFragment : BaseFragment<FragmentNotificationsBinding,NotificationsViewModel>(){

    override fun initView(view: View?) {
        super.initView(view)
//        binding.textNotifications.text = vm.text.value
//        YDLog.logd(binding.textNotifications.text.toString())

        val sectionsPagerAdapter = NotificSectionsPagerAdapter(context(), childFragmentManager)
        val viewPager: ViewPager =  binding.viewPager
        viewPager.adapter = sectionsPagerAdapter
        val tabs: TabLayout =  binding.tabs
        tabs.setupWithViewPager(viewPager)

        binding.tabs.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{
            override fun onTabSelected(tab: TabLayout.Tab?) {
                YDLog.logd(tab!!.position.toString())
//                binding.viewPager.get(tab!!.position)
                binding.viewPager.currentItem = tab!!.position
//                binding.viewPager.offscreenPageLimit = tab!!.position
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {

            }

            override fun onTabReselected(tab: TabLayout.Tab?) {

            }

        })
    }
    override fun vmClass(): Class<NotificationsViewModel> {
        return NotificationsViewModel::class.java
    }

    override fun binding(inflater: LayoutInflater, container: ViewGroup?): FragmentNotificationsBinding {
        return  FragmentNotificationsBinding.inflate(layoutInflater)
    }

}